<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryRef" :inline="true" label-width="auto" v-show="showSearch">
            <el-form-item label="所属项目名称" prop="outdoorProjectName">
                <el-input
                    v-model="queryParams.outdoorProjectName"
                    placeholder="请输入所属项目名称"
                    clearable
                    @keyup.enter="handleQuery"
                />
            </el-form-item>
            <el-form-item label="昵称" prop="plateNumber">
                <el-input
                    v-model="queryParams.plateNumber"
                    placeholder="请输入昵称"
                    clearable
                    @keyup.enter="handleQuery"
                />
            </el-form-item>

						<el-form-item label="创建时间" prop="dateRange">
						  <el-date-picker
						    v-model="dateRange"
						    type="datetimerange"
						    range-separator="-"
						    start-placeholder="开始日期"
						    value-format="yyyy-MM-dd HH:mm:ss"
						    style="width:333px;"
						    :default-time="['00:00:00','23:59:59']"
						    end-placeholder="结束日期">
						  </el-date-picker>
						</el-form-item>

            <el-form-item >
                <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
                <el-button icon="Refresh" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="list">
            <el-table-column label="支付订单id" align="center" prop="payOrderId"/>
            <el-table-column label="交易单号" align="center" prop="channelOrderNo"/>
            <el-table-column label="追缴单号" align="center" prop="recoveryNo"/>
            <el-table-column label="所属项目名称" align="center" prop="projectNames"/>
            <el-table-column label="车牌号" align="center" prop="plateNumber" :show-overflow-tooltip="true"/>
            <el-table-column label="支付类型" align="center" prop="payChannel">
              <template slot-scope="{row}">
                  <dict-tag :options="dict.type.luce_pay_type" :value="row.payChannel"/>
              </template>
            </el-table-column>
            <el-table-column label="缴费状态" align="center" prop="payStatus">
                <template slot-scope="{row}">
                    <dict-tag :options="dict.type.pay_status_options" :value="row.payStatus" />
                </template>
            </el-table-column>
            <el-table-column label="缴费金额" align="center" prop="payAmount"/>
            <el-table-column label="缴费笔数" align="center" prop="payCount"/>
            <el-table-column label="缴费时间" align="center" prop="payTime"/>
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="300">
               <template slot-scope="{row}">
                  <el-button link type="primary" icon="Delete"
                  @click="handleDetail(row)" v-hasPermi="['system:eaOutdoorRecoveryDetail:list']" >查看详情</el-button>
               </template>
            </el-table-column>
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />

      <!-- 详情弹框 -->
      <el-dialog :title="title" :visible.sync="open" width="70%" append-to-body destroy-on-close>
        <div class="diy-mx-8">
          <div>
            <el-table :data="detailList" v-loading="popLodding" :header-cell-style="{fontSize:'14px'}">
              <el-table-column prop="outdoorProjectName" align="center" label="所属项目名称"></el-table-column>
              <el-table-column prop="pkParkRecordId" align="center" label="停车记录ID"></el-table-column>
              <el-table-column prop="plateNumber" align="center" label="车牌号码"></el-table-column>
              <el-table-column prop="parkName" align="center" label="片区"></el-table-column>
              <el-table-column prop="parkingNo" align="center" label="泊位编号"></el-table-column>
              <el-table-column prop="entryTime" align="center" label="入场时间"></el-table-column>
              <el-table-column prop="leavingTime" align="center" label="离场时间"></el-table-column>
              <el-table-column prop="parkingDuration" align="center" label="停车时长"></el-table-column>
              <el-table-column prop="payAmount" align="center" label="支付金额"></el-table-column>
              <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="300">
                 <template slot-scope="{row}">
                    <el-button link type="primary" icon="Delete"
                    @click="handleRefund(row)" v-if="form.payStatus == 1" v-hasPermi="['system:eaOutdoorRefund:add']" >退款</el-button>
                 </template>
              </el-table-column>
            </el-table>
            <pagination
              v-show="popTotal>0"
              :total="popTotal"
              :page.sync="popQueryParams.pageNum"
              :limit.sync="popQueryParams.pageSize"
              @pagination="eaOutdoorRecoveryDetail"
            />
          </div>
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button @click="open =false">关 闭</el-button>
        </div>
      </el-dialog>

      <!-- 申请退款对话框-->
      <el-dialog :title="refundtitle" :visible.sync="openRefundApply" width="1000px" append-to-body>
        <el-form ref="form_refund" :model="form_refund" :rules="rules_refund" label-width="108px">
          <el-row>
            <el-col :span="24">
              <el-form-item label="退款金额" prop="refundAmount">
                <el-input-number v-model="form_refund.refundAmount" :precision="2" :step="0.1" :min="0"></el-input-number>
              </el-form-item>
            </el-col>
            <!-- <el-col :span="24">
              <el-form-item label="退款原因" prop="remark">
                <el-input v-model="form_refund.remark" type="textarea"></el-input>
              </el-form-item>
            </el-col> -->
          </el-row>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="applySubmit">确 定</el-button>
          <el-button @click="openRefundApply =false">关 闭</el-button>
        </div>
      </el-dialog>
    </div>
</template>

<script >
import * as api from "@/api/roadside/recovery";

export default {
  name: 'Recovery',
  dicts: ['pay_status_options','pay_type_options','luce_pay_type'],
  components: {  },
  data() {
    return {
      form: {},// 表单参数
      form_refund:{},
      rules_refund:{
        refundAmount: [
          {required: true, message: "退款金额不能为空", trigger: "blur"},
        ],
      },
      // 弹出层标题
      title: "",
      refundtitle:'',
      // 是否显示弹出层
      open: false,
      openRefundApply:false,
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      queryParams: {// 查询参数
        pageNum: 1,
        pageSize: 10,
      },
      // 总条数
      total: 0,
      list:[],//页面数据
      dateRange:[],
      detailList:[],//详情数据
      popQueryParams: {// 查询参数
        pageNum: 1,
        pageSize: 10,
      },
      popTotal: 0,
      popLodding:false,
    };
  },
  mounted(){
    this.getList()
  },
  methods: {
    applySubmit(){//退款确定
      this.$refs["form_refund"].validate(valid => {
        if (valid) {
          if (this.form_refund.refundAmount > this.form_refund.payAmount) {
            this.$message.error('退款金额应小于等于支付金额哈');
            return false;
          }
          api.eaOutdoorRecoveryRefund(this.form_refund).then((response) => {
            if (response.code != 200) return;
            this.$modal.msgSuccess("操作成功");
            this.openRefundApply = false;
          });
        }
      });
    },
    handleRefund(row){//退款点击
      this.openRefundApply = true;
      this.refundtitle = "申请退款";
      this.form_refund = {
        recoveryDetailId:row.id,
        payAmount:row.payAmount,
      };
    },
    handleDetail(e){//配置详情跳转
      this.form = {...e}
      this.popQueryParams.recoveryId = e.id
      this.eaOutdoorRecoveryDetail()
      this.open = true
    },
    async eaOutdoorRecoveryDetail(){
      this.popLodding = true
      let res = await api.eaOutdoorRecoveryDetail(this.popQueryParams)
      let rows = res.rows || []
      this.detailList = rows
      this.popTotal = res.total || 0
      this.popLodding = false
    },
    getList() {
      this.loading = true;
      let queryParams = {...this.queryParams}
      if(!this.dateRange) this.dateRange = []
      if(this.dateRange.length) {
        queryParams.startTime = this.dateRange[0]
        queryParams.endTime = this.dateRange[1]
      }
      api.listEaOutdoorRecovery(queryParams).then(response => {
        this.list = response.rows || [];
        this.total = response.total || 0;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.queryParams = {// 查询参数
        pageNum: 1,
        pageSize: 10,
      }
      this.resetForm("queryRef");
      this.handleQuery();
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(api.EXPORT_URL, {
          ...this.queryParams
      }, `recharge_${new Date().getTime()}.xlsx`);
    }
  }
}
</script>
